from typing import List
from fastapi import HTTPException, status, Depends
import json
from sqlalchemy.orm import Session
from table.role import Role
from table.group import Group
from common.custom_log import my_logger
from paramsModel.common import Page
from paramsModel.role import RoleParams
from common.response import CustomPageResponse, CustomApiResponse, response_code, responseCode


class GroupModel:

    @classmethod
    def get_list(cls, db: Session, page: Page, status: str = '0'):
        group_total = cls.get_total_roles(db, status=status)
        if group_total == 0:
            return CustomPageResponse.pageBack(total=group_total)
        grouplist = db.query(Group).filter(Group.del_flag == status).offset(page['start']).limit(page['pagesize']).all()
        return CustomPageResponse.pageBack(total=group_total, list=cls.formatterBackList(self=cls, queryList=grouplist),
                                           pagesize=page['pagesize'])

    # 获取用户的总数
    @classmethod
    def get_total_roles(cls, db: Session, status: str = '0'):
        return db.query(Group).filter(Group.del_flag == status).count()